<template>
	<view class="content">
		<view class="swiper-block">
				<image src="https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/home/jq-erq/banner.png" class="img"></image>
		</view>
		<view class="block">
			<view class="middle">
				<view class="label-item1">
					<picker class="form-ctrl FZHZGBJ" :range="areaList" range-key="data" :value="city" @change="bindType" style="color: #FD704C;">
						{{city==-1? "区域" :areaList[city]['data']}}
					</picker>
					<!-- <view class="iconfont icon-icon_xialaxuanze" style="font-size: 12px;"></view> -->
					<image src="https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/home/jq-erq/select.png" mode=""></image>
				</view>
				<view class="intention" @click="navigate('/page_other/intention/index')">
					没有找到合适的培训？点击添加培训意向
				</view>
			</view>
			<template v-if="list.length>0">
				<view class="menu-block block" v-for="(item,index) in list" :key="item.id" @click="navigate1(index)">
					<view class="top">
						<view class="title" style="margin: 0;">
							{{item.trainInstitution}}
						</view>
					</view> 
					<view class="bottom">
						<image src="https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/home/jq-erq/address1.png" style="width: 30rpx;height: 30rpx;margin-right: 10rpx;"></image>
						<view class="address">
							{{item.trainAddress}}
						</view>
					</view>
				</view>
			</template>
			<view v-else class="empty">暂无数据</view>
		</view>
	</view>
</template>

<script>
	import {
		getAreasList,
		getUserTrainList,
	} from '@/api/train.js';
	export default {
		data() {
			return {
				// type:1,
				page:1,
				limit:10,
				city: -1,
				areaList: [{
					id: 0,
					data: "全部"
				},],
				newsList:[],
				list:[],
			}
		},
		methods: {
			navigate1(index) {
				const item = this.list[index];
				uni.navigateTo({
					url: `/page_other/train/entrepreneurTrain/schoolDetail?id=${item.id}&latitude=${this.latitude}&longitude=${this.longitude}`
				})
			},
			getList() {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				uni.getLocation({
					success: (current) => {
						this.latitude = current.latitude;
						this.longitude = current.longitude;
						uni.setStorageSync('latitude', this.latitude)
						uni.setStorageSync('longitude', this.longitude)
						getUserTrainList({
							page: this.page,
							limit: this.limit,
							latitude: this.latitude,
							longitude: this.longitude,
							city: this.city,
							type: this.type
						}).then((data) => {
							uni.hideLoading()
							this.list = data.list
						})
					},
					fail: (e) => {
						this.showToast('获取位置失败，请重试！');
					}
				})
			},
			getAreasList(typeId) {
				getAreasList().then((data) => {
					for (let i = 0; i < data.length; i++) {
						const current = data[i];
						this.areaList.push({
							id: current.id,
							data: current.data
						})
					}
			
				}).catch((data) => {
					console.log(res)
				})
			},
			bindType(e) {
				this.city = e.detail.value
				this.getList()
			},
			bindActive(index) {
				this.tabActive = index
				if (this.tabActive == 0) {
					this.getList()
				}
				if (this.tabActive == 2) {
					this.getList1()
				}
			},
			navigate(url) {
				uni.navigateTo({
					url
				})
			},

		},
		onLoad(e) {
			this.type = e.type
			this.getList()
			this.getAreasList()
		},
	}
</script>

<style lang="scss">
	page {
		background-color: #fafafa;
	}
	.middle{
		display: flex;
	}
	.label-item1 {
		display: flex;
		flex-direction: row;
		align-items: center;
		padding: 10rpx 10rpx;
		font-size: 28rpx;
		// color: #FE7526;
		// background: #FDECE5;
		margin: auto 10rpx;
		text-align: center;
		width: 210rpx;
		height: 50rpx;
		.form-ctrl {
			width: 83rpx;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
			margin: 0 auto;
			margin: 0 10rpx 0 28rpx;
			font-size: 28rpx;

		}
		image{
			width: 20rpx;
			height: 20rpx;
		}
	
	}
	.intention{
		width: 90%;
		height: 70rpx;
		font-size: 25rpx;
		// margin: 20rpx auto;
		background-color: #FC704C;
		color: #fff;
		border-radius: 40rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.menu-block {
		margin-top: 30rpx;
		background: #fff;
		border-radius: 12px;
		padding: 30rpx;
		.title{
			font-weight: 900;
			font-size: 32rpx;
			line-height: 52rpx;
			width: 100%;
			margin: 0;
			overflow: hidden;
			text-overflow: ellipsis;
			display: -webkit-box;
			-webkit-line-clamp: 2;
			-webkit-box-orient: vertical;
		}
		.top{
			display: flex;
			.title{
				font-size: 32rpx;
				color: #1A1A1A;
			}
		}
		.bottom{
			display: flex;
			align-items: center;
			justify-content: left;
			margin-top: 20rpx;
			.address{
				width: calc(100% - 40rpx);
				font-size: 28rpx;
				color: #767676;
				overflow:hidden;
				white-space:nowrap;
				text-overflow:ellipsis;
			}
		}
	}
	.swiper-block {
		width: 100%;
		height: 280rpx;
		box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.2);
		border-radius: 20rpx;
		margin-bottom: 20rpx;
		.img{
			width: 100%;
			height: 100%;
		}
	}
		
	
	.content {
		width: 100%;
		padding: 30rpx;

		.menu-item {
			display: flex;
			align-items: center;
			margin: 40rpx 0 30rpx 0;
			padding: 0 30rpx;

			.tab-item {
				font-size: 36rpx;
				margin-right: 30rpx;
				font-weight: bold;
			}

			.tab-item.active {
				font-size: 36rpx;
				font-weight: bold;
				margin-right: 30rpx;
				color: red;
			}
		}

		.block {
			width: 100%;
			.title {
				margin: 40rpx 0 30rpx 0;

				.t-left {
					display: flex;
					align-items: center;

					.pre-icon {
						width: 15rpx;
						height: 37rpx;
						background-color: #ff7626;
						border-radius: 16rpx;
						margin-right: 10rpx;
					}

					.name {
						font-weight: bold;
					}
				}

				.more {
					font-size: 30rpx;
					color: #999;
				}
			}

		}

		
	}
</style>